package com.junyidao.game.controller;

import com.junyidao.game.constant.OperLogConstant;
import com.junyidao.game.core.LoginInfo;
import com.junyidao.game.core.annotation.Action;
import com.junyidao.game.pojo.SysUser;
import com.junyidao.game.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * Created by zzh on 2016/8/28.
 */
@Controller
@RequestMapping("/userSet")
public class UserSetController extends BaseController {

    @Autowired
    private UserService userService;

    @RequestMapping
    @Action(desc = "进入账号设置页面")
    public ModelAndView list() {
        ModelAndView result = new ModelAndView("system/user_set");
        SysUser user = LoginInfo.getUser();
        result.addObject("user", user);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/updatePassword")
    @Action(operType = OperLogConstant.USER_SET_PASSWORD, desc = "修改密码", needLog = true)
    public Map<String, Object> updatePassword(String password, String passwordOld) {
        userService.updatePassword(password, passwordOld);
        return resultSucess(null);
    }

    @ResponseBody
    @RequestMapping(value = "/updateBind")
    @Action(operType = OperLogConstant.USER_SET_BIND, desc = "修改账号绑定信息", needLog = true)
    public Map<String, Object> updateBind(String mobil, String email) {
        userService.updateBind(mobil, email);
        return resultSucess(null);
    }
}
